Ext.ns('cceaf.util');

Ext.define('cceaf.util.StockHelper',{
	//extjs cmd只能通过类查找，需定义空类
});

cceaf.util.StockHelper = (function() {
	
	return {
		
		/**
		 * 根据产品ID得到产品信息
		 * 
		 * @param productid 产品ID
		 * @return 产品的JSON对象
		 */
		getProduct: function(productid){
			var productJSON;
			
			if(productid != null){  
				Ext.Ajax.request({
					url: 'stockDataProvider!getProduct.action',
					async: false,
					success: function(response){
						productJSON = eval("(" + response.responseText + ")");
					},
					//timeout: 100,
					params: {productid:productid}
				});
		    }
			
			if(productJSON == null){
				productJSON = {};
			}
			return productJSON;
		},

		/**
		 * 根据客户ID得到客户信息
		 * 
		 * @param customerid 客户ID
		 * @return 客户的JSON对象
		 */
		getCustomer: function(customerid){
			var customerJSON;
			
			if(customerid != null){  
				Ext.Ajax.request({
					url: 'stockDataProvider!getCustomer.action',
					async: false,
					success: function(response){
						customerJSON = eval("(" + response.responseText + ")");
					},
					//timeout: 100,
					params: {customerid:customerid}
				});
		    }
			
			if(customerJSON == null){
				customerJSON = {};
			}
			return customerJSON;
		},
		
		
		/**
		 * 得到入库单的下一个单据编号
		 * 
		 * @return 下一个单据编号
		 */
		getNextInBillno: function(){
			var nextBillno = "";

			Ext.Ajax.request({
				url: 'stockDataProvider!getNextInBillno.action',
				async: false,
				success: function(response){
					nextBillno = response.responseText.ltrim();
					//nextBillno = response.responseText;
					return nextBillno;
				},
				//timeout: 100,
				params: {}
			});
			
			return nextBillno;
		},
		
		
		/**
		 * 得到出库单的下一个单据编号
		 * 
		 * @return 下一个单据编号
		 */
		getNextOutBillno: function(){
			var nextBillno = "";

			Ext.Ajax.request({
				url: 'stockDataProvider!getNextOutBillno.action',
				async: false,
				success: function(response){
					nextBillno = response.responseText.ltrim();
					//nextBillno = response.responseText;
					return nextBillno;
				},
				//timeout: 100,
				params: {}
			});
			
			return nextBillno;
		}
		
	};
	
}());